<?php
/**
 * 会员评价
 *
 * @copyright  Copyright (c) 2007-2015 ShopNC Inc. (http://www.shopnc.net)
 * @license    http://www.shopnc.net
 * @link       http://www.shopnc.net
 * @since      File available since Release v1.1
 */



defined('ByShopWWI') or exit('Access Invalid!');

class member_evaluateControl extends mobileMemberControl {

    public function __construct(){
        parent::__construct();
    }
    
    /**
     * 评论
     */
    public function indexOp() {
        $order_id =intval($_POST['order_id']);
		$model_order = Model('order');
        $model_store = Model('store');
        //$model_evaluate_goods = Model('evaluate_goods');
       // $model_evaluate_store = Model('evaluate_store');
		//获取订单信息
        $order_info = $model_order->getOrderInfo(array('order_id' => $order_id));
		//判断订单身份
       // if($order_info['buyer_id'] != $this->member_info['member_id']) {
			//output_error('您不能评价此订单');
            //showMessage(Language::get('wrong_argument'),'index.php?act=member_order','html','error');
       // }
		 //查询店铺信息
		 $store_info = $model_store->getStoreInfoByID($order_info['store_id']);
		  //获取订单商品
        $order_goods = $model_order->getOrderGoodsList(array('order_id'=>$order_id)); 
        output_data(array('store_info' => $store_info['store_name'], 'order_goods' => $order_goods));
    }
    
    /**
     * 评论保存
     */
    public function saveOp() {
        $order_id = intval($_POST['order_id']);
		$goods_id = intval($_POST['goods_id']);
		$model_order = Model('order');
		$model_evaluate_goods = Model('evaluate_goods');
        $model_evaluate_store = Model('evaluate_store');
		$order_info = $model_order->getOrderInfo(array('order_id' => $order_id));
		$order_goods = $model_order->getOrderGoodsList(array('order_id'=>$order_id,'goods_id'=>$goods_id)); 
         //如果未评分，默认为5分
         $evaluate_score = intval($_POST['score']);
         if($evaluate_score <= 0 || $evaluate_score > 5) {
             $evaluate_score = 5;
         }
         //默认评语
         $evaluate_comment = $_POST['comment'];
         if(empty($evaluate_comment)) {
             $evaluate_comment = '不错哦';
         }
		 $geval_image =  $_POST['evaluate_image']; 
         $evaluate_goods_info = array();
         $evaluate_goods_info['geval_orderid'] = $order_id;
         $evaluate_goods_info['geval_orderno'] = $order_info['order_sn'];
         $evaluate_goods_info['geval_ordergoodsid'] = $order_goods['rec_id'];
         $evaluate_goods_info['geval_goodsid'] = $goods_id;
         $evaluate_goods_info['geval_goodsname'] = $order_goods['goods_name'];
         $evaluate_goods_info['geval_goodsprice'] = $order_goods['goods_price'];
         $evaluate_goods_info['geval_goodsimage'] = $order_goods['goods_image'];
         $evaluate_goods_info['geval_scores'] = $evaluate_score;
         $evaluate_goods_info['geval_content'] = $evaluate_comment;
         $evaluate_goods_info['geval_isanonymous'] = $_POST['anony'];//是否匿名
         $evaluate_goods_info['geval_addtime'] = TIMESTAMP;
         $evaluate_goods_info['geval_storeid'] = $order_info['store_id'];
         $evaluate_goods_info['geval_storename'] = $order_info['store_name'];
         $evaluate_goods_info['geval_frommemberid'] = $this->member_info['member_id'];
         $evaluate_goods_info['geval_frommembername'] = $this->member_info['member_name'];
         $evaluate_goods_info['geval_image'] = $geval_image;
         $evaluate_goods_info['geval_content_again'] = '';
         $evaluate_goods_info['geval_image_again'] = '';
         $evaluate_goods_info['geval_explain_again'] = '';

         $evaluate_goods_array[] = $evaluate_goods_info;

         $goodsid_array[] = $goods_id;
		$return['state'] = $model_evaluate_goods->addEvaluateGoodsArray($evaluate_goods_array, $goodsid_array);
		//店铺评价
		 $store_desccredit = intval($_POST['store_desccredit']);
            if($store_desccredit <= 0 || $store_desccredit > 5) {
                $store_desccredit= 5;
            }
            $store_servicecredit = intval($_POST['store_servicecredit']);
            if($store_servicecredit <= 0 || $store_servicecredit > 5) {
                $store_servicecredit = 5;
            }
            $store_deliverycredit = intval($_POST['store_deliverycredit']);
            if($store_deliverycredit <= 0 || $store_deliverycredit > 5) {
                $store_deliverycredit = 5;
            }
            //添加店铺评价
            //if (!$store_info['is_own_shop']) {
                $evaluate_store_info = array();
                $evaluate_store_info['seval_orderid'] = $order_id;
                $evaluate_store_info['seval_orderno'] = $order_info['order_sn'];
                $evaluate_store_info['seval_addtime'] = time();
                $evaluate_store_info['seval_storeid'] = $order_info['store_id'];
                $evaluate_store_info['seval_storename'] = $order_info['store_name'];
                $evaluate_store_info['seval_memberid'] = $this->member_info['member_id'];
                $evaluate_store_info['seval_membername'] = $this->member_info['member_name'];
                $evaluate_store_info['seval_desccredit'] = $store_desccredit;
                $evaluate_store_info['seval_servicecredit'] = $store_servicecredit;
                $evaluate_store_info['seval_deliverycredit'] = $store_deliverycredit;
           // }
           $return['state1']= $model_evaluate_store->addEvaluateStore($evaluate_store_info);
        //$return = Logic('member_evaluate')->validation($order_id, $this->member_info['member_id']);
        if ($return['state']&& $return['state']) {
            output_error('失败');
        } else {
            output_data('1');
        }
    }
    
    /**
     * 追评
     */
    public function againOp() {
		$order_id = intval($_POST['evaluate_id']);
		$goods_id = intval($_POST['goods_id']);
		//$model_order = Model('order');
		$model_evaluate_goods = Model('evaluate_goods');
       //获取订单商品
        $evaluate_goods = $model_evaluate_goods->getEvaluateGoodsList(array('geval_orderid'=>$order_id,'geval_goodsid'=>$goods_id));
		output_data($evaluate_goods);
		/* $order_id = intval($_GET['order_id']);
        $return = Logic('member_evaluate')->validationAgain($order_id, $this->member_info['member_id']);
        if (!$return['state']) {
            output_error($return['msg']);
        }
        extract($return['data']);
        $store = array();
        $store['store_id'] = $store_info['store_id'];
        $store['store_name'] = $store_info['store_name'];
        $store['is_own_shop'] = $store_info['is_own_shop'];
        
        output_data(array('store_info' => $store, 'evaluate_goods' => $evaluate_goods));*/
    }

    /**
     * 追加评价保存
     */
    public function save_againOp() {
       /* $order_id = intval($_POST['order_id']);
        $return = Logic('member_evaluate')->validationAgain($order_id, $this->member_info['member_id']);
        if (!$return['state']) {
            output_error($return['msg']);
        }
        extract($return['data']);

        $return = Logic('member_evaluate')->saveAgain($_POST, $order_info, $evaluate_goods);*/
		$evaluate_id = intval($_POST['evaluate_id']);
		$goods_id = intval($_POST['goods_id']);
		//$model_order = Model('order');
		$model_evaluate_goods = Model('evaluate_goods');
        //$model_evaluate_store = Model('evaluate_store');
		//$order_info = $model_order->getOrderInfo(array('order_id' => $order_id));
		//$order_goods = $model_order->getOrderGoodsList(array('order_id'=>$order_id,'goods_id'=>$goods_id)); 
        
         //默认评语
         $evaluate_comment = $_POST['comment'];
         if(empty($evaluate_comment)) {
             $evaluate_comment = '不错哦';
         }
		 //图片上传
		 $geval_image =  $_POST['evaluate_image']; 
		 
         $evaluate_goods_info = array();
          $evaluate_goods_info['geval_content_again'] = $evaluate_comment;
          $evaluate_goods_info['geval_addtime_again'] = TIMESTAMP;
          $evaluate_goods_info['geval_image_again'] = $geval_image;

        
         $goodsid_array[] = $goods_id;
		 $goodsid_array[] = 
		$return['state'] = $model_evaluate_goods->editEvaluateGoods($evaluate_goods_info, array('geval_id' => $evaluate_id));
        if(!$return['state']) {
            output_data($return['msg']);
        } else {
            output_data('1');
        }
    }
    
    /**
     * 虚拟订单评价
     */
    public function vrOp() {
		$order_id =intval($_POST['order_id']);
		$model_order = Model('vr_order');
        $model_store = Model('store');
        //$model_evaluate_goods = Model('evaluate_goods');
       // $model_evaluate_store = Model('evaluate_store');
		//获取订单信息
        $order_info = $model_order->getOrderInfo(array('order_id' => $order_id));
		//判断订单身份
       // if($order_info['buyer_id'] != $this->member_info['member_id']) {
			//output_error('您不能评价此订单');
            //showMessage(Language::get('wrong_argument'),'index.php?act=member_order','html','error');
       // }
		 //查询店铺信息
		 $store_info = $model_store->getStoreInfoByID($order_info['store_id']);
		  //获取订单商品
        $order_goods = $model_order->getOrderGoodsList(array('order_id'=>$order_id)); 
        output_data(array('store_info' => $store_info['store_name'], 'order_goods' => $order_goods));
        /*$order_id = intval($_GET['order_id']);
        $return = Logic('member_evaluate')->validationVr($order_id, $this->member_info['member_id']);
        if (!$return['state']) {
            output_error($return['msg']);
        }
        extract($return['data']);
        output_data(array('order_info' => $order_info));*/
    }
    
    /**
     * 虚拟订单评价保存
     */
    public function save_vrOp() {
		$order_id = intval($_POST['order_id']);
		$goods_id = intval($_POST['goods_id']);
		$model_order = Model('vr_order');
		$model_evaluate_goods = Model('evaluate_goods');
        $model_evaluate_store = Model('evaluate_store');
		$order_info = $model_order->getOrderInfo(array('order_id' => $order_id));
		$order_goods = $model_order->getOrderGoodsList(array('order_id'=>$order_id,'goods_id'=>$goods_id)); 
         //如果未评分，默认为5分
         $evaluate_score = intval($_POST['score']);
         if($evaluate_score <= 0 || $evaluate_score > 5) {
             $evaluate_score = 5;
         }
         //默认评语
         $evaluate_comment = $_POST['comment'];
         if(empty($evaluate_comment)) {
             $evaluate_comment = '不错哦';
         }
		 $geval_image =  $_POST['evaluate_image']; 
         $evaluate_goods_info = array();
         $evaluate_goods_info['geval_orderid'] = $order_id;
         $evaluate_goods_info['geval_orderno'] = $order_info['order_sn'];
         $evaluate_goods_info['geval_ordergoodsid'] = $order_goods['rec_id'];
         $evaluate_goods_info['geval_goodsid'] = $goods_id;
         $evaluate_goods_info['geval_goodsname'] = $order_goods['goods_name'];
         $evaluate_goods_info['geval_goodsprice'] = $order_goods['goods_price'];
         $evaluate_goods_info['geval_goodsimage'] = $order_goods['goods_image'];
         $evaluate_goods_info['geval_scores'] = $evaluate_score;
         $evaluate_goods_info['geval_content'] = $evaluate_comment;
         $evaluate_goods_info['geval_isanonymous'] = $_POST['anony'];//是否匿名
         $evaluate_goods_info['geval_addtime'] = TIMESTAMP;
         $evaluate_goods_info['geval_storeid'] = $order_info['store_id'];
         $evaluate_goods_info['geval_storename'] = $order_info['store_name'];
         $evaluate_goods_info['geval_frommemberid'] = $this->member_info['member_id'];
         $evaluate_goods_info['geval_frommembername'] = $this->member_info['member_name'];
         $evaluate_goods_info['geval_image'] = $geval_image;
         $evaluate_goods_info['geval_content_again'] = '';
         $evaluate_goods_info['geval_image_again'] = '';
         $evaluate_goods_info['geval_explain_again'] = '';

         $evaluate_goods_array[] = $evaluate_goods_info;

         $goodsid_array[] = $goods_id;
		$return['state'] = $model_evaluate_goods->addEvaluateGoodsArray($evaluate_goods_array, $goodsid_array);
		//店铺评价
		 $store_desccredit = intval($_POST['store_desccredit']);
            if($store_desccredit <= 0 || $store_desccredit > 5) {
                $store_desccredit= 5;
            }
            $store_servicecredit = intval($_POST['store_servicecredit']);
            if($store_servicecredit <= 0 || $store_servicecredit > 5) {
                $store_servicecredit = 5;
            }
            $store_deliverycredit = intval($_POST['store_deliverycredit']);
            if($store_deliverycredit <= 0 || $store_deliverycredit > 5) {
                $store_deliverycredit = 5;
            }
            //添加店铺评价
            //if (!$store_info['is_own_shop']) {
                $evaluate_store_info = array();
                $evaluate_store_info['seval_orderid'] = $order_id;
                $evaluate_store_info['seval_orderno'] = $order_info['order_sn'];
                $evaluate_store_info['seval_addtime'] = time();
                $evaluate_store_info['seval_storeid'] = $order_info['store_id'];
                $evaluate_store_info['seval_storename'] = $order_info['store_name'];
                $evaluate_store_info['seval_memberid'] = $this->member_info['member_id'];
                $evaluate_store_info['seval_membername'] = $this->member_info['member_name'];
                $evaluate_store_info['seval_desccredit'] = $store_desccredit;
                $evaluate_store_info['seval_servicecredit'] = $store_servicecredit;
                $evaluate_store_info['seval_deliverycredit'] = $store_deliverycredit;
           // }
           $return['state1']= $model_evaluate_store->addEvaluateStore($evaluate_store_info);
        //$return = Logic('member_evaluate')->validation($order_id, $this->member_info['member_id']);
        if ($return['state']&& $return['state']) {
            output_error('失败');
        } else {
            output_data('1');
        }
        /*$order_id = intval($_POST['order_id']);
        $return = Logic('member_evaluate')->validationVr($order_id, $this->member_info['member_id']);
        if (!$return['state']) {
            output_error($return['msg']);
        }
        extract($return['data']);

        $return = Logic('member_evaluate')->saveVr($_POST, $order_info, $store_info, $this->member_info['member_id'], $this->member_info['member_name']);
        if(!$return['state']) {
            output_data($return['msg']);
        } else {
            output_data('1');
        }*/
    }
}
